package com.yan.kfgl.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.yan.kfgl.model.vo.ShownUser;
import com.yan.kfgl.service.biz.facade.UserService;

public class DwrUserAction {
	private ShownUser user;
	private UserService userService;
	private String password;
	
	public ShownUser showPersonalCenter(){
		user = userService.findShownUserByName(user);
		return user;
	}
	
	public boolean logout() {
		boolean flag = true;
		HttpServletRequest request = ServletActionContext.getRequest();
		String sessID = request.getSession().getId();
		HttpSession session = request.getSession();

		try {
			Map<String, ShownUser> userLogin = (Map<String, ShownUser>) session
					.getAttribute("userLogin");
			if (userLogin == null) {
				userLogin = new HashMap<String, ShownUser>();
			}
			userLogin.remove(sessID);
			session.setAttribute("userLogin", userLogin);
		} catch (Exception e) {
			flag = false;
		}

		return flag;
	}
	
	public ShownUser getUser() {
		return user;
	}

	public void setUser(ShownUser user) {
		this.user = user;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
